import { defHttp } from '/@/utils/http/axios';

//list = '/api-rpa',
enum Api {
  list = '/api-rpa/spider/list',
  save = '/api-rpa/spider/save',
  delete = '/api-rpa/spider/remove',
  xml = '/api-rpa/spider/xml',
  history = '/api-rpa/spider/history',
  shapes = '/api-rpa/spider/shapes',
  datasource = '/api-rpa/datasource/all',
  run = '/api-rpa/spider/run',
  cron = '/api-rpa/spider/cron',
  recentTime = '/api-rpa/spider/recent5TriggerTime',
  getNoticeWay = '/api-rpa/flowNotice/getNoticeWay',
  find = '/api-rpa/flowNotice/find',
  saveNotice = '/api-rpa/flowNotice/save',
  start = '/api-rpa/spider/start',
  stop = '/api-rpa/spider/stop',
  saveGroup = '/api-rpa/spider/systemId',
  allOcrTypes = '/api-rpa/ocr/allOcrTypes',
  emailList= '/api-rpa/mail/list',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 获取当前流程的xml
 * @param params
 */
export const getXml = (params) => {
  return defHttp.get({ url: Api.xml, params },{isTransformResponse: false});
};
/**
 * 保存当前流程的xml
 * @param params
 */
export const saveFlow = (params) => {
  return defHttp.post({ url: Api.save, params }, {isTransformResponse: false});
};
/**
 * 删除单个流程
 */
export const removeRequest = (params, handleSuccess) => {
  return defHttp.post({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 查询id的历史记录
 * @param params
 */
export const historyFlow = (params) => {
  return defHttp.get({ url: Api.history, params });
};
/**
 * @param params
 */
export const loadExtShapes = () => {
  return defHttp.post({ url: Api.shapes });
};
/**
 * @param params
 */
export const loadDataSource = (params) => {
  return defHttp.get({ url: Api.datasource, params });
};
/**
 * 最近5次运行时间
 * @param params
 */
export const recent5TriggerTime = (params) => {
  return defHttp.get({ url: Api.recentTime, params }, { joinParamsToUrl: true });
};
/**
 * 手动运行
 * @param params
 */
export const runRequest = (params, handleSuccess) => {
  return defHttp.get({ url: Api.run, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 修改cron配置
 * @param params
 */
export const cronRequest = (params, handleSuccess) => {
  return defHttp.post({ url: Api.cron, params }).then(() => {
    handleSuccess();
  });
};
/**
 * 获取通知方式列表
 * @param params
 */
export const getNoticeWayList = (params) => {
  return defHttp.get({ url: Api.getNoticeWay, params });
};
/**
 * 获取通知类型
 * @param params
 */
export const getFlowNotice = (params) => {
  return defHttp.post({ url: Api.find, params }, { joinParamsToUrl: true });
};
/**
 * 保存流程通知
 * @param params
 */
export const saveFlowNotify = (params) => {
  return defHttp.post({ url: Api.saveNotice, params });
};
/**
 * 启动任务
 * @param params
 */
 export const startRequest = (params, handleSuccess) => {
  return defHttp.get({ url: Api.start, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 停止任务
 * @param params
 */
 export const stopRequest = (params, handleSuccess) => {
  return defHttp.get({ url: Api.stop, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 保存流程分组
 * @param params
 */
export const saveFlowGroup = (params) => {
  return defHttp.post({ url: Api.saveGroup, params });
};
/**
 * @param params
 */
export const loadOcrTypes = (params) => {
  return defHttp.get({ url: Api.allOcrTypes, params });
};
/**
 * @param params
 */
export const loadEmail = (params) => {
  return defHttp.get({ url: Api.emailList, params });
};
